package cn.edu.stu.syllabus.oa.list;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import javax.inject.Inject;

import butterknife.BindView;
import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.base.BaseActivity;
import cn.edu.stu.syllabus.repository.oa.OaSearchInfo;
import cn.edu.stu.syllabus.utils.ActivityUtils;
import cn.edu.stu.syllabus.utils.ExtraNameJoiner;

public class OaSearchResultActivity extends BaseActivity {

    private static final String EXTRA_SEARCH_INFO = ExtraNameJoiner.join(
            OaSearchResultActivity.class, OaSearchInfo.class.getSimpleName()
    );

    @BindView(R.id.topView)
    View mTopView;

    private OaSearchInfo mOaSearchInfo;

    @Inject
    OaPresenter mOaPresenter;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_oa_search_result;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setTitle("搜索结果");

        mOaSearchInfo = getIntent().getParcelableExtra(EXTRA_SEARCH_INFO);

        mTopView.getLayoutParams().height = getStatusBarHeight();

        OaFragment oaFragment = (OaFragment) getSupportFragmentManager()
                .findFragmentById(R.id.contentFrame);
        if (oaFragment == null) {
            oaFragment = OaFragment.newInstance();
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager()
                    , oaFragment, R.id.contentFrame);
        }
        setOnToolbarDoubleClickListener(oaFragment);

        DaggerOaComponent.builder()
                .oaPresenterModule(new OaPresenterModule(oaFragment, mOaSearchInfo))
                .build().inject(this);

    }

    public static Intent newIntent(Context context, OaSearchInfo oaSearchInfo) {
        Intent intent = new Intent(context, OaSearchResultActivity.class);
        intent.putExtra(EXTRA_SEARCH_INFO, oaSearchInfo);
        return intent;
    }
}
